/*
* <T>代表泛型
* */

import java.util.ArrayList;
import java.util.List;

class Alg<T extends Comparable<T>>{//extends Comparable<T>是泛型的上界，也可以说是扩展
    public Object[] array = new Object[10];

    public T findMax(T[] array){
        T max = array[0];
        for (int i = 0; i < array.length; i++) {
            if(array[i].compareTo(max)>0){
                max = array[i];
            }
        }
        return max;
    }
}

class Alg2 {
    //泛型方法
    public static <T extends Comparable<T>> T findMax(T[] array) {
        T max = array[0];
        for (int i = 1; i < array.length; i++) {
            if(array[i].compareTo(max) > 0) {
                max = array[i];
            }
        }
        return max;
    }
}





class Tarray<T>{
    public Object[] array = new Object[10];
    //public T[] array = new T[10]; 不允许 实例化一个泛型数组
    //public T[] array = (T[])new Object[10];//这样写也不好！！

    public T get(int pos) {
        return (T)this.array[pos];
    }
    public void set(int pos,Object val) {
        this.array[pos] = val;
    }
}

public class Test3 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        ArrayList<String> list1 = new ArrayList<>();
        Integer[] array = {1,13,51,71,19};
        Integer ret = Alg2.<Integer>findMax(array);
        System.out.println(ret);
    }
    public static void main2(String[] args) {
        Alg<Integer> alg2 = new Alg<>();
        Integer[] array = {1,13,51,71,19};

        Integer ret = alg2.findMax(array);
        System.out.println(ret);
    }
    public static void main1(String[] args) {
        Tarray<String> tarray = new Tarray<>();
        tarray.set(0,"hh");

        String s = tarray.get(0);
        System.out.println(s);

        Tarray<Integer> tarray2 = new Tarray<>();
        tarray2.set(0,1);
        int i = tarray2.get(0);
        System.out.println(i);
    }
}
